package de.baumann.browser.activitys.center

import android.content.Context
import android.content.DialogInterface
import android.content.Intent
import android.view.Menu
import android.view.MenuItem
import android.view.View
import de.baumann.browser.OdinGlideModule
import de.baumann.browser.R
import de.baumann.browser.activitys.center.WithdrawalsRecordActivity.Companion.startWithdrawalsRecordActivity
import de.baumann.browser.activitys.hash.RechargeActivity.Companion.startRechargeActivity
import de.baumann.browser.base.BaseOdinActivity
import de.baumann.browser.iview.IWalletView
import de.baumann.browser.present.WalletPresenter
import de.baumann.browser.utils.Constants.LICENCE_AVAILABLE
import de.baumann.browser.utils.getLicenceStatus
import de.baumann.browser.views.dialog.CanNotWithdrawDialog
import de.baumann.browser.views.dialog.LicenceNotActiveDialog
import kotlinx.android.synthetic.main.activity_wallet.*
import kotlinx.android.synthetic.main.include_tool_bar.*

@Deprecated("废弃")
class WalletActivity : BaseOdinActivity<IWalletView, WalletPresenter>(), IWalletView {

    private var odinOver = 0.00

    companion object {
        const val WITHDRAWCODE = 203
        fun startWalletActivity(context: Context) {
            context.startActivity(Intent(context, WalletActivity::class.java))
        }
    }

    override fun getLayout(): Int {
        return R.layout.activity_wallet
    }

    override fun initView() {
        initToolbar(commToolBar, commTitle)
        btnWithdraw.setOnClickListener {
            val licenceStatus = getLicenceStatus()
            if (licenceStatus != LICENCE_AVAILABLE) {
                LicenceNotActiveDialog(mContext, View.OnClickListener {
                    TurnVipActivity.startTurnVipActivity(mContext)
                }).show()
                return@setOnClickListener
            }

            if (odinOver < 600) {
                showShortToast(getString(R.string.less_than_600))
                return@setOnClickListener
            }

            presenter.isCanWihdraw()
        }

        btnRecharg.setOnClickListener {
            startRechargeActivity(mContext)
        }
    }

    override fun createPresenter(): WalletPresenter {
        return WalletPresenter()
    }

    override fun createView(): IWalletView {
        return this
    }

    override fun initData() {
        presenter.getUserBasicInfo()
        presenter.getWalletData()
    }

    override fun getTitleText(): String {
        return getString(R.string.wallet)
    }

    override fun onCreateOptionsMenu(menu: Menu?): Boolean {
        menuInflater.inflate(R.menu.menu_withdraw_record, menu)
        return super.onCreateOptionsMenu(menu)
    }

    override fun onOptionsItemSelected(item: MenuItem?): Boolean {
        startWithdrawalsRecordActivity(mContext)
        return super.onOptionsItemSelected(item)
    }

    override fun setLoginName(loginName: String?) {
        tvWalletLoginName.text = loginName
    }

    override fun setHeadhUrl(headUrl: String?) {
        OdinGlideModule.loadWithCropAndCircle(mContext, headUrl, ivWalletHead, R.drawable.icon_head)
    }

    override fun setPoolName(poolName: String?) {
        tvWalletPoolName.text = poolName
    }

    override fun setOdinFreeze(freeze: String) {
        tvWalletOdinFreeze.text = freeze
    }

    override fun setOdinOver(over: String) {
        odinOver = over.toDouble()
        tvWalletOdinOver.text = over
    }

    override fun setLicenceStr(licenceStr: String) {

    }

    override fun isCanWithdraw(canWithdraw: Boolean) {
        if (canWithdraw) {
            startActivityForResult(Intent(mContext, WithdrawActivity::class.java).apply {
                putExtra("odinOver", odinOver)
            }, WITHDRAWCODE)
            return
        }
        CanNotWithdrawDialog(mContext).show()
    }
}
